import { Button, Form, Input, message } from "antd";
import { apiLogin } from "../../api";
import Cookie from "js-cookie";
// import  React, {useEffect} from 'react'

const Login = () => {
  const onFinish = (val) => {
    apiLogin(val).then((res) => {
      message.success(res.msg);

      Cookie.set("token", res.token);

      setTimeout(() => {
        window.location.href = "/";
      }, 1000);
    });
    console.log(val);
  };

  return (
    <div className="public">
      <Form name="basic" onFinish={onFinish} autoComplete="off">
        <Form.Item
          label="用户名"
          name="username"
          rules={[{ required: true, message: "请输入用户名" }]}
        >
          <Input />
        </Form.Item>

        <Form.Item
          label="密码"
          name="password"
          rules={[{ required: true, message: "请输入密码" }]}
        >
          <Input.Password />
        </Form.Item>
        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
          <Button type="primary" htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
};

export default Login;
